import requests
import json

class YunPian(object):
    def __init__(self, api_key):
        self.api_key = api_key
        self.single_send_url = 'https://sms.yunpian.com/v2/sms/single_send.json'

    def send_sms(self, code, mobile):
        parmas = {
            'apikey': self.api_key,
            'mobile': mobile,
            'text': '【刘强1】您的验证码是{code}。如非本人操作，请忽略本短信'.format(code=code)
        }

        response = requests.post(self.single_send_url,data=parmas)
        res_dict = json.loads(response.text)
        return res_dict


if __name__=='__main__':
    yunpian =YunPian('c991c31567fcf8c7d13e15423cb94a2a')
    yunpian.send_sms('1201','18228086397')
